package com.oitsm.dispatcher;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.oitsm.dispatcher.task.SysTasker;
import com.oitsm.utils.PropUtil;
/**
 * 系统任务执行器
 * @author Arab Runner
 * Jul 24, 2011 2:32:33 PM
 */
public class SysTaskExcutor {
	private static BlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<Runnable>();
	
	private static  ThreadPoolExecutor threadPoolExecutor = null;
	
	private static int keepAliveTime = PropUtil.getInteger("sys.threadPool.keepAliveTime", 3);
	private static int threadCount = PropUtil.getInteger("sys.threadPool.threadCount", 20);
	
	public static void init(){
		threadPoolExecutor = new ThreadPoolExecutor(threadCount, threadCount, keepAliveTime, TimeUnit.SECONDS, taskQueue); 	
	}
	
	public static void addTask(SysTasker t){
		threadPoolExecutor.execute(t);
	}
}
